package edu.ycu.aladdin.collector.api.entity.weibo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 微博数据 爬虫任务.
 *
 * @author <a href="mailto:wangruihuano@gmail.com">王瑞环</a>
 * @since 2019-04-05 19:59
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class UserInfoTaskQueue extends BaseWeiBoCrawlerTaskQueue<String> {

    /**
     * 微博用户id队列
     */
    protected Queue<String> userIdQueue = new LinkedList<>();

    public UserInfoTaskQueue() {
        init();
    }

    private void init() {
        super.setCreateTime(System.currentTimeMillis());
    }

    /**
     * 开始和结束 (start,end]
     * @param start 不包括start
     * @param end 结束
     */
    public UserInfoTaskQueue(long start, long end) {
        this();
        start++;
        if (start <= end) {
            for (long tmp = start; tmp <= end; tmp++) {
                userIdQueue.add(String.valueOf(tmp));
            }
        }
    }

    @Override
    public Queue<String> getTaskQueue() {
        return this.userIdQueue;
    }

    @Override
    public String pollOne() {
        return userIdQueue.poll();
    }
}

